export default {
	namespaced:true,
	state(){
		return {
			cityname:'定位中...'
		}
	},
	mutations:{
		initLocMut(state,name){
			state.cityname = name
		}
	},
	actions:{
		initLocAct(context){
			uni.getLocation({
				success: ({longitude,latitude}) => { //获取经纬度
					console.log(longitude,latitude);
					uni.request({ //根据经纬度，让高德API解析位置信息
						url:`https://restapi.amap.com/v3/geocode/regeo?key=e0119d3cbd6eb284068484cadeb50e07&location=${longitude},${latitude}`,
						success:(res)=>{
							console.log(res);
							let {province} = res.data.regeocode.addressComponent
							context.commit('initLocMut',province)
						}
					})
				}
			})
		}
	}
}